/**
 * jQuery-based messagebox toaster widget 
 *
	// css:
	#toaster { z-index: 9999; top: 2px; left: 25%; right: 25%; position: absolute; position: fixed; }
	#toaster .toast { color:#FFF; font: bold 10pt Tahoma, Helvetica, sans-serif; overflow:hidden; margin: 0 auto 5px; position: relative;
		border: 1px solid rgba(255,255,255,0.7); -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px;  
		-moz-box-shadow: 0 2px 2px 1px rgba(0,0,0,.4); -webkit-box-shadow: 0 2px 2px 1px rgba(0,0,0,.4); box-shadow: 0 2px 2px 1px rgba(0,0,0,.4);
	}
	#toaster .toast .toast-closer { position: absolute; right: 3px; top: 2px; height:16px; width:16px; cursor:pointer; background:url(../img/icons/toaster-closer.png) 0 0 no-repeat; }
	#toaster .toast .toast-content { padding: 3px 26px; display: block; background-position: 4px 4px; background-repeat:no-repeat; word-wrap: break-word; }
	#toaster .toast-error { background: #B82906; background: rgba(184,41,6,.9); }
	#toaster .toast-error .toast-content { background-image: url(../img/icons/toaster-alert.png); }
	#toaster .toast-info,.toast-success { background: #4C8004; background: rgba(76,128,4,.9); }
	#toaster .toast-success .toast-content, .toast-info .toast-content {  background-image: url(../img/icons/toaster-info.png); }  
 */



/**
 * Show a toast
 * 
 * @param {String} conf		info text for toast
 * OR
 * @param {Object} conf		toast config object:
 * 		type {String}			toast type ['info'|'error'], default 'info'
 * 		text {String}			toast text, default ''
 * 		delay {Number}			toast timeout, default 5
 * 		autoClose {Boolean}		auto close toast [true|false], default true
 */
var Toaster = function(conf){
	if (!conf) return;
	var self=this, toaster = $('#toaster');
	if (typeof conf === 'string') conf = { text: conf }; 
	this.conf = $.extend({ type:'info', delay:5, autoClose: true }, conf);
	if(!toaster.length) toaster = $('<div id="toaster"></div>').appendTo('body');
	this.toast = $('<div style="display:none" class="toast toast-'+this.conf.type+'"><span class="toast-closer" title="Dismiss"></span><span class="toast-content">'+this.conf.text+'</span></div>');
	this.toast.delegate('.toast-closer', 'click', function(){self.close.call(self);});
	this.toast.appendTo(toaster).fadeIn('slow');
	if (this.conf.autoClose) this.msgTimeout = setTimeout(function(){self.close();},this.conf.delay*1000);
};
/**
 * Close a toast instance
 */
Toaster.prototype.close = function(){
	if (this.msgTimeout){ clearTimeout(this.msgTimeout); this.msgTimeout=null; }	 
	this.toast.fadeOut(function(){$(this).remove();});
};


/**
 * Shows a default info toast
 *
 * @param {String} conf		text for msgbox
 * OR
 * @param {Object} conf		config object for msgbox
 */
var msgbox = function(conf){new Toaster(conf);};


/**
 * Shows a default error toast
 * @param {Object} txt		error text to display
 */
var msgerror = function(txt){new Toaster({type:'error', text:txt});};
